package com.philip.demo;

import org.bytedeco.javacpp.tools.Logger;
import org.bytedeco.opencv.global.opencv_imgcodecs;
import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.Rect;
import org.bytedeco.opencv.opencv_core.Size;
import org.slf4j.LoggerFactory;

import static org.bytedeco.opencv.global.opencv_imgproc.resize;

/**
 * 辅助类
 */
public class P_FaceHandleHelper {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(P_FaceHandleHelper.class);

    public class videoRecorder {


    }

    public class ClippedFaceSaver{
        private static final String SUFFIX_PIC = ".jpg";
        private static final String DEFAULT_PATH = "D:\\test\\capture\\";
        private int pic_width = 100;
        private int pic_height=100;

        public ClippedFaceSaver(){

        }

        public ClippedFaceSaver(String width,String height){

        }

        public boolean saveClippedFacePic (Mat originalImage, Rect rect, String picName) {
            LOGGER.info("running saveClippedFacePic ...");
            Mat sub = originalImage.rowRange(rect.y(), rect.y() + rect.height()).colRange(rect.x(), rect.x() + rect.width());
            Mat mat = new Mat();
            Size size = new Size(100, 100);
            resize(sub, mat, size);
            boolean success= opencv_imgcodecs.imwrite(getPicName(picName),mat);
            LOGGER.info("保存截取人脸图片成功: {}",success);
            return success;
        }

        private String getPicName(String picName) {
            StringBuilder savePicName = new StringBuilder();
            savePicName.append(DEFAULT_PATH);
            savePicName.append(picName);
            savePicName.append(SUFFIX_PIC);
            return savePicName.toString();
        }
    }





}
